package demo.controller;

import org.springframework.web.bind.annotation.*;

/**
 * 演示@RequestMapping注解内的参数（常用）
 * @Param value 指定映射的URL
 * @Param method 指定URL请求的HTTP方法
 * @Param params 指定URL请求中接收的参数
 * @Param produce 表示返回的内容类型
 */
@RestController
public class ControllerTest1 {
    @RequestMapping(value = "/test1")
    public String test1Page(){
        return "test1Page";
    }

    @RequestMapping(value = "/test2", method = RequestMethod.GET)
    public String test2Page(){
        return "test2Page";
    }

    @RequestMapping(value = "/test3", method = RequestMethod.POST)
    public String test3Page(){
        return "test3Page";
    }

    @RequestMapping(value = "/test4", params = {"id", "name=Peter"})
    public String test4Page(){
        return "test4Page";
    }

    /**
     *参数前的注解@PathVariable可将此接收的参数与URL中括起来的同名变量绑定
     */
    @RequestMapping("/getPersonById/{id}")
    public String getPersonById(@PathVariable String id){
        return "the ID: " + id;
    }

    @RequestMapping("/getPersonByIdAndName/{id}/{name}")
    public String getPersonByIdAndName(@PathVariable String id, @PathVariable String name){
        return "ID: " + id + "  Name: " + name;
    }

    /**
     * 参数前的注解@RequestParam可将接收的参数与请求中的params中同名参数相绑定
     */
    @RequestMapping(value = "/getAccountByIdAndName", params = {"id", "name"})
    public String getAccountByIdAndName(@RequestParam String id, @RequestParam String name){
        return "ACCOUNT!!!   " + "ID: " + id + "  Name: " + name;
    }

}
